home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Visual Basic new SourceCode and Projects / Midi Piano / MidiModule.bas < prev    next >
Encoding:
BASIC Source File  |  1999-11-27  |  9.2 KB  |  134 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. Public Const MAXPNAMELEN = 32             ' Maximum product name length
  5.  
  6. ' Error values for functions used in this sample. See the function for more information
  7. Public Const MMSYSERR_BASE = 0
  8. Public Const MMSYSERR_BADDEVICEID = (MMSYSERR_BASE + 2)     ' device ID out of range
  9. Public Const MMSYSERR_INVALPARAM = (MMSYSERR_BASE + 11)     ' invalid parameter passed
  10. Public Const MMSYSERR_NODRIVER = (MMSYSERR_BASE + 6)        ' no device driver present
  11. Public Const MMSYSERR_NOMEM = (MMSYSERR_BASE + 7)           ' memory allocation error
  12.  
  13. Public Const MMSYSERR_INVALHANDLE = (MMSYSERR_BASE + 5)     ' device handle is invalid
  14. Public Const MIDIERR_BASE = 64
  15. Public Const MIDIERR_STILLPLAYING = (MIDIERR_BASE + 1)      ' still something playing
  16. Public Const MIDIERR_NOTREADY = (MIDIERR_BASE + 3)          ' hardware is still busy
  17. Public Const MIDIERR_BADOPENMODE = (MIDIERR_BASE + 6)       ' operation unsupported w/ open mode
  18.  
  19. 'User-defined variable the stores information about the MIDI output device.
  20. Type MIDIOUTCAPS
  21.    wMid As Integer                   ' Manufacturer identifier of the device driver for the MIDI output device
  22.                                      ' For a list of identifiers, see the Manufacturer Indentifier topic in the
  23.                                      ' Multimedia Reference of the Platform SDK.
  24.    
  25.    wPid As Integer                   ' Product Identifier Product of the MIDI output device. For a list of
  26.                                      ' product identifiers, see the Product Identifiers topic in the Multimedia
  27.                                      ' Reference of the Platform SDK.
  28.    
  29.    vDriverVersion As Long            ' Version number of the device driver for the MIDI output device.
  30.                                      ' The high-order byte is the major version number, and the low-order byte is
  31.                                      ' the minor version number.
  32.                                      
  33.    szPname As String * MAXPNAMELEN   ' Product name in a null-terminated string.
  34.    
  35.    wTechnology As Integer            ' One of the following that describes the MIDI output device:
  36.                                      '     MOD_FMSYNTH-The device is an FM synthesizer.
  37.                                      '     MOD_MAPPER-The device is the Microsoft MIDI mapper.
  38.                                      '     MOD_MIDIPORT-The device is a MIDI hardware port.
  39.                                      '     MOD_SQSYNTH-The device is a square wave synthesizer.
  40.                                      '     MOD_SYNTH-The device is a synthesizer.
  41.                                      
  42.    wVoices As Integer                ' Number of voices supported by an internal synthesizer device. If the
  43.                                      ' device is a port, this member is not meaningful and is set to 0.
  44.                                      
  45.    wNotes As Integer                 ' Maximum number of simultaneous notes that can be played by an internal
  46.                                      ' synthesizer device. If the device is a port, this member is not meaningful
  47.                                      ' and is set to 0.
  48.                                      
  49.    wChannelMask As Integer           ' Channels that an internal synthesizer device responds to, where the least
  50.                                      ' significant bit refers to channel 0 and the most significant bit to channel
  51.                                      ' 15. Port devices that transmit on all channels set this member to 0xFFFF.
  52.                                      
  53.    dwSupport As Long                 ' One of the following describes the optional functionality supported by
  54.                                      ' the device:
  55.                                      '     MIDICAPS_CACHE-Supports patch caching.
  56.                                      '     MIDICAPS_LRVOLUME-Supports separate left and right volume control.
  57.                                      '     MIDICAPS_STREAM-Provides direct support for the midiStreamOut function.
  58.                                      '     MIDICAPS_VOLUME-Supports volume control.
  59.                                      '
  60.                                      ' If a device supports volume changes, the MIDICAPS_VOLUME flag will be set
  61.                                      ' for the dwSupport member. If a device supports separate volume changes on
  62.                                      ' the left and right channels, both the MIDICAPS_VOLUME and the
  63.                                      ' MIDICAPS_LRVOLUME flags will be set for this member.
  64. End Type
  65.  
  66. Declare Function midiOutGetNumDevs Lib "winmm" () As Integer
  67. ' This function retrieves the number of MIDI output devices present in the system.
  68. ' The function returns the number of MIDI output devices. A zero return value means
  69. ' there are no MIDI devices in the system.
  70.  
  71. Declare Function midiOutGetDevCaps Lib "winmm.dll" Alias "midiOutGetDevCapsA" (ByVal uDeviceID As Long, lpCaps As MIDIOUTCAPS, ByVal uSize As Long) As Long
  72. ' This function queries a specified MIDI output device to determine its capabilities.
  73. ' The function requires the following parameters;
  74. '     uDeviceID-     unsigned integer variable identifying of the MIDI output device. The
  75. '                    device identifier specified by this parameter varies from zero to one
  76. '                    less than the number of devices present. This parameter can also be a
  77. '                    properly cast device handle.
  78. '     lpMidiOutCaps- address of a MIDIOUTCAPS structure. This structure is filled with
  79. '                    information about the capabilities of the device.
  80. '     cbMidiOutCaps- the size, in bytes, of the MIDIOUTCAPS structure. Use the Len
  81. '                    function with the MIDIOUTCAPS variable as the argument to get
  82. '                    this value.
  83. '
  84. ' The function returns MMSYSERR_NOERROR if successful or one of the following error values:
  85. '     MMSYSERR_BADDEVICEID    The specified device identifier is out of range.
  86. '     MMSYSERR_INVALPARAM     The specified pointer or structure is invalid.
  87. '     MMSYSERR_NODRIVER       The driver is not installed.
  88. '     MMSYSERR_NOMEM          The system is unable to load mapper string description.
  89.  
  90. Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long
  91. ' The function closes the specified MIDI output device. The function requires a
  92. ' handle to the MIDI output device. If the function is successful, the handle is no
  93. ' longer valid after the call to this function. A successful function call returns
  94. ' MMSYSERR_NOERROR.
  95.  
  96. ' A failure returns one of the following:
  97. '     MIDIERR_STILLPLAYING  Buffers are still in the queue.
  98. '     MMSYSERR_INVALHANDLE  The specified device handle is invalid.
  99. '     MMSYSERR_NOMEM        The system is unable to load mapper string description.
  100.  
  101. Declare Function midiOutOpen Lib "winmm.dll" (lphMidiOut As Long, ByVal uDeviceID As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
  102. ' The function opens a MIDI output device for playback. The function requires the
  103. ' following parameters
  104. '     lphmo-               Address of an HMIDIOUT handle. This location is filled with a
  105. '                          handle identifying the opened MIDI output device. The handle
  106. '                          is used to identify the device in calls to other MIDI output
  107. '                          functions.
  108. '     uDeviceID-           Identifier of the MIDI output device that is to be opened.
  109. '     dwCallback-          Address of a callback function, an event handle, a thread
  110. '                          identifier, or a handle of a window or thread called during
  111. '                          MIDI playback to process messages related to the progress of
  112. '                          the playback. If no callback is desired, set this value to 0.
  113. '     dwCallbackInstance-  User instance data passed to the callback. Set this value to 0.
  114. '     dwFlags-Callback flag for opening the device. Set this value to 0.
  115. '
  116. ' The function returns MMSYSERR_NOERROR if successful or one of the following error values:
  117. '     MIDIERR_NODEVICE-       No MIDI port was found. This error occurs only when the mapper is opened.
  118. '     MMSYSERR_ALLOCATED-     The specified resource is already allocated.
  119. '     MMSYSERR_BADDEVICEID-   The specified device identifier is out of range.
  120. '     MMSYSERR_INVALPARAM-    The specified pointer or structure is invalid.
  121. '     MMSYSERR_NOMEM-         The system is unable to allocate or lock memory.
  122.  
  123. Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
  124. ' This function sends a short MIDI message to the specified MIDI output device. The function
  125. ' requires the handle to the MIDI output device and a message is packed into a doubleword
  126. ' value with the first byte of the message in the low-order byte. See the code sample for
  127. ' how to create this value.
  128. '
  129. ' The function returns MMSYSERR_NOERROR if successful or one of the following error values:
  130. '     MIDIERR_BADOPENMODE-  The application sent a message without a status byte to a stream handle.
  131. '     MIDIERR_NOTREADY-     The hardware is busy with other data.
  132. '     MMSYSERR_INVALHANDLE- The specified device handle is invalid.
  133.  
  134.